[#macro accountListView]
<div>
    <el-dialog title="提示" :visible.sync="dialogVisible" width="30%">
        <span>确认要删除该条数据吗?</span>
        <span slot="footer" class="dialog-footer">
            <el-button @click="dialogVisible = false">取 消</el-button>
            <el-button type="primary" @click="handleClose">确 定</el-button>
        </span>
    </el-dialog>
    <el-dialog title="提示" :visible.sync="createVisible" width="30%">

        <el-form ref="ruleForm" :rules="rules" :model="form" label-width="80px">
            <el-row :gutter="10">
                <el-col :span="24">
                    <el-form-item label="账号" size="mini" prop="no">
                        <el-input v-model="form.no" name="no">
                        </el-input>
                    </el-form-item>
                </el-col>
                <el-col :span="24">
                    <el-form-item label="账号类型" size="mini" prop="bindType">
                        <el-select size="small" style="width: 100%;" v-model="form.bindType" filterable clearable
                            placeholder="请选择">
                            <el-option v-for="item in bindTypeOptions" :key="item.id" :label="item.name"
                                :value="item.id">
                            </el-option>
                        </el-select>
                    </el-form-item>
                </el-col>
            </el-row>
        </el-form>
        <span slot="footer" class="dialog-footer">
            <el-button @click="createVisible = false">取 消</el-button>
            <el-button type="primary" @click="submitForm">确 定</el-button>
        </span>
    </el-dialog>
    <div class="data-content1">
        <div class="tool-add">
            <el-button type="primary" size="small" @click="addView">新增</el-button>
        </div>

        <el-table v-loading="loading" :data="tableData.list" @cell-click="showView" @sort-change="changeTableSort"
            style="width: 100%;font-size: 12px;">
            <el-table-column label="账号" prop="no" width="100">
            </el-table-column>
            <el-table-column label="账号类型" prop="bindTypeName" width="100">
            </el-table-column>
            <el-table-column label="登录次数" prop="loginSize" width="100">
            </el-table-column>
            <el-table-column label="创建时间" prop="addDate">
            </el-table-column>
            <el-table-column width="100" align="center" fixed="right" label="操作">
                <template slot-scope="scope">
                    <el-button type="danger" size="mini" style="cursor: pointer;" @click="deleteData(scope.row)">删除
                    </el-button>
                </template>
            </el-table-column>
        </el-table>

        <div class="page">
            <el-pagination background :current-page="searchObject.no" :page-sizes="[10, 20, 50, 100]"
                :page-size="tableData.size" :pager-count="5" layout="total, sizes, prev, pager, next, jumper"
                :page-count="tableData.totalPage" :total="tableData.total" @size-change="sizeChange"
                @current-change="pageChange">
            </el-pagination>
        </div>
    </div>
</div>
[/#macro]
[#macro accountListConfig]
<script type="text/x-template" id="my-account-list">
	[@accountListView /]
</script>
<script type="text/javascript">
    var accountListConfig = {};
    accountListConfig.template = "#my-account-list";
    accountListConfig.methods = config.basicMethod();


    accountListConfig.methods.addView = function () {
        this.createVisible = true;
    }
    accountListConfig.methods.editView = function (row) {
        var self = this;
        var data = {};
        data.id = row.id;
        this.$router.push({ path: 'update', query: data });

    }

    accountListConfig.methods.changeTableSort = function (column) {
        this.searchObject.sortField = column.prop;
        if ("descending" == column.order) {
            this.searchObject.sortMethod = "desc";
        }
        else if ("ascending" == column.order) {
            this.searchObject.sortMethod = "asc";
        }
        else {
            this.searchObject.sortMethod = "";
        }
        this.getSearchList();
    }
    accountListConfig.methods.showView = function (row, column, cell, event) {
        if (cell.cellIndex > 0) {
            return;
        }
        var param = {};
        param.id = row.id;
        var self = this;
        this.$router.push({ path: 'view', query: param });

    }

    accountListConfig.methods.sizeChange = function (event) {
        this.searchObject.size = event;
        this.getSearchList();
    }
    accountListConfig.methods.pageChange = function (index) {
        this.searchObject.no = index;
        this.getSearchList();
    }
    accountListConfig.methods.getSearchList = function () {
        this.loading = true;
        var data = this.searchObject, that = this;
        $.post("${siteurl}tenantRest/userbind/search.htm", data, function (result) {
            if (result.code == 0) {
                that.tableData = result;
            }
            setTimeout(function () {
                that.loading = false;
            }, 300)
        });
    }
    accountListConfig.methods.search = function () {
        this.searchObject.no = 1;
        this.getSearchList();
    }
    accountListConfig.methods.clearData = function () {
        this.searchObject.school = "";
        this.searchObject.name = "";
        this.searchObject.phone = "";
        this.searchObject.classInfo = "";
        this.searchObject.parent = "";
    }
    accountListConfig.methods.deleteData = function (event) {
        this.selectId = event.id;
        this.dialogVisible = true;
    }

    accountListConfig.methods.handleClose = function (done) {
        this.dialogVisible = false;
        var self = this;
        if (self.selectId) {
            var params = {};
            params.id = self.selectId;
            this.postData("${siteurl}tenantRest/userbind/delete.htm", params, function (res) {
                if (res.code == 0) {
                    self.$message({
                        message: '删除数据成功',
                        type: 'success'
                    });
                    self.getSearchList();
                } else {
                    self.$message.error(res.msg);
                }
            });
        }

    }

    accountListConfig.computed = {};
    accountListConfig.computed.classInfoOptions = function () {
        return this.$store.state.classInfoOptions;
    };
    accountListConfig.computed.schoolOptions = function () {
        return this.$store.state.schoolOptions;
    };

    accountListConfig.data = function () {
        return {
            searchObject: {
                no: 1,
                size: 10,
                school: '',
                name: '',
                phone: '',
                classInfo: '',
                user: ''
            },
            dialogVisible: false,
            createVisible: false,
            defaultProps: {
                children: 'children',
                label: 'name'
            },
            loading: false,
            tableData: {},
            form: { no: "", bindType: "" },
            bindTypeOptions: [{ id: "phone", name: "手机号" },
            { id: "email", name: "邮箱" },
            { id: "account", name: "账号" },
            { id: "other", name: "其他" }],
            rules: {
                no: [
                    { required: true, message: '请输入账号', trigger: 'blur' }
                ],
                bindType: [
                    { required: true, message: '请选择账号类型', trigger: 'blur' }
                ]
            }

        }
    };

    accountListConfig.methods.submitForm = function (done) {
        var self=this;
        this.$refs["ruleForm"].validate(function (valid) {
            if (valid) {
                self.restPassword();
            } else {
                console.log('error submit!!');
                return false;
            }
        });
    }
    accountListConfig.methods.resetForm = function (event) {
        this.$refs['ruleForm'].resetFields()
    }

    

    accountListConfig.methods.restPassword = function (done) {
       var self=this;
       var params=this.form;
       this.postData("${siteurl}tenantRest/userbind/create.htm", params, function (res) {
            if (res.code == 0) {
                self.$message({
                    message: '添加账号成功',
                    type: 'success'
                });
                self.getSearchList();
                self.createVisible=false;
            } else {
                self.$message.error(res.msg);
            }
        });

    }
    accountListConfig.mounted = function () {
        var id = this.$route.query.id;
        var self = this;
        self.searchObject.user = id;
        self.form.user=id;
        this.getSearchList();
    }
    var accountListView = Vue.component('list-account-view', accountListConfig);
</script>
[/#macro]